package model.purchasing;

import java.math.BigDecimal;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import model.inventory.Hadiah;
import model.inventory.Item;
import model.inventory.ItemHpp;
import model.inventory.Unit;
import utility.typeSafe.JenisBonus;

@Entity
@Table(name="trs_order_detail", schema="purchasing")
public class OrderDetail  implements java.io.Serializable {

     private OrderDetailId id;
     private OrderMst orderMst;
     private Item item;
     private Hadiah hadiah;
     private BigDecimal qtyCrt;
     private BigDecimal qtyPcs;
     private BigDecimal qtyBonus;
     private BigDecimal price;
     private BigDecimal diskon;
     private BigDecimal ppn;
     private BigDecimal amount;
     private String jenisBonus;
     private Integer fraksi;
     private Unit unit;
     private Integer fraksiBonus;
     private Integer top;
     private String diskonDesc;
     private String bonusDesc;
     private ItemHpp itemHpp;
     private BigDecimal stok;

    public OrderDetail() {
        this.id = new OrderDetailId();
        this.qtyCrt = BigDecimal.ZERO;
        this.qtyPcs = BigDecimal.ZERO;
        this.qtyBonus= BigDecimal.ZERO;
        this.price = BigDecimal.ZERO;
        this.stok = BigDecimal.ZERO;
        this.diskon=BigDecimal.ZERO;
        this.ppn=BigDecimal.ZERO;
        this.amount=BigDecimal.ZERO;
        this.jenisBonus = JenisBonus.BPB.toString();
        this.top=0;
        this.fraksi=1;
        this.fraksiBonus=1;
        this.diskonDesc="";
        this.bonusDesc="";
//        this.item = new Item();
//        this.hadiah = new Hadiah();
    }

    public OrderDetail(OrderDetailId id) {
        this.id = id;
    }
       
    @EmbeddedId
    @AttributeOverrides( {
        @AttributeOverride(name="id", column=@Column(name="id", nullable=false) ), 
        @AttributeOverride(name="item_id", column=@Column(name="item_id", nullable=false) ) } )
    public OrderDetailId getId() {
        return this.id;
    }
    
    public void setId(OrderDetailId id) {
        this.id = id;
    }
    
    @ManyToOne
    @JoinColumn(name="id", nullable=false, insertable=false, updatable=false)
    public OrderMst getOrderMst() {
        return this.orderMst;
    }
    
    public void setOrderMst(OrderMst orderMst) {
        this.orderMst = orderMst;
    }
    
    @ManyToOne(fetch= FetchType.LAZY)
    @JoinColumn(name="item_id", nullable=false, insertable=false, updatable=false)
    public Item getItem() {
        return this.item;
    }
    
    public void setItem(Item item) {
        this.item = item;
    }
    
    @ManyToOne(fetch= FetchType.LAZY)
    @JoinColumn(name="hadiah_id")
    public Hadiah getHadiah() {
        return this.hadiah;
    }
    
    public void setHadiah(Hadiah hadiah) {
        this.hadiah = hadiah;
    }
    
    @Column(name="qty_crt", precision=13)
    public BigDecimal getQtyCrt() {
        return this.qtyCrt;
    }
    
    public void setQtyCrt(BigDecimal qtyCrt) {
        this.qtyCrt = qtyCrt;
    }
    
    @Column(name="qty_pcs", precision=13)
    public BigDecimal getQtyPcs() {
        return this.qtyPcs;
    }
    
    public void setQtyPcs(BigDecimal qtyPcs) {
        this.qtyPcs = qtyPcs;
    }
    
    @Column(name="qty_bonus", precision=13)
    public BigDecimal getQtyBonus() {
        return this.qtyBonus;
    }
    
    public void setQtyBonus(BigDecimal qtyBonus) {
        this.qtyBonus = qtyBonus;
    }
    
    @Column(name="price", precision=13)
    public BigDecimal getPrice() {
        return this.price;
    }
    
    public void setPrice(BigDecimal price) {
        this.price = price;
    }
    
    @Column(name="diskon", precision=13, scale=3)
    public BigDecimal getDiskon() {
        return this.diskon;
    }
    
    public void setDiskon(BigDecimal diskon) {
        this.diskon = diskon;
    }
    
    @Column(name="ppn", precision=13, scale=3)
    public BigDecimal getPpn() {
        return this.ppn;
    }
    
    public void setPpn(BigDecimal ppn) {
        this.ppn = ppn;
    }
    
    @Column(name="amount", precision=13)
    public BigDecimal getAmount() {
        return this.amount;
    }
    
    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }
    
    @Column(name="jenis_bonus", length=100)
    public String getJenisBonus() {
        return this.jenisBonus;
    }
    
    public void setJenisBonus(String jenisBonus) {
        this.jenisBonus = jenisBonus;
    }

    @ManyToOne(fetch= FetchType.LAZY)
    @JoinColumn(name="unit_id")
    public Unit getUnit() {
        return unit;
    }

    public void setUnit(Unit unit) {
        this.unit = unit;
    }
    
    @Column(name="fraksi")
    public Integer getFraksi() {
        return this.fraksi;
    }
    
    public void setFraksi(Integer fraksi) {
        this.fraksi = fraksi;
    }
    
    @Column(name="fraksi_bonus")
    public Integer getFraksiBonus() {
        return this.fraksiBonus;
    }
    
    public void setFraksiBonus(Integer fraksiBonus) {
        this.fraksiBonus = fraksiBonus;
    }
    
    @Column(name="top")
    public Integer getTop() {
        return this.top;
    }
    
    public void setTop(Integer top) {
        this.top = top;
    }
    
    @Column(name="diskon_desc", length=100)
    public String getDiskonDesc() {
        return this.diskonDesc;
    }
    
    public void setDiskonDesc(String diskonDesc) {
        this.diskonDesc = diskonDesc;
    }
    
    @Column(name="bonus_desc", length=100)
    public String getBonusDesc() {
        return this.bonusDesc;
    }
    
    public void setBonusDesc(String bonusDesc) {
        this.bonusDesc = bonusDesc;
    }
    
    @Transient
    public ItemHpp getItemHpp() {
        return this.itemHpp;
    }
    
    public void setItemHpp(ItemHpp itemHpp) {
        this.itemHpp = itemHpp;
    }

    @Transient
    public BigDecimal getStok() {
        return stok;
    }

    public void setStok(BigDecimal stok) {
        this.stok = stok;
    }

    
}


